package com.wdc.贪心;

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;

@SuppressWarnings("all")
public class E11Leetcode406 {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, new Comparator<int[]>() {
            @Override
            public int compare(int[] a, int[] b) {
                if (a[0] == b[0]) return a[1] - b[1];
                return b[0] - a[0];
            }
        });

        LinkedList<int[]> res = new LinkedList<>();

        for (int[] p : people) {
            res.add(p[1], p);
        }

        return res.toArray(new int[people.length][]);
    }


    public static void main(String[] args) {
        int[][] arr = {{7,0},{4,4},{7,1},{5,0},{6,1},{5,2}};   // arr[i] = [hi ,ki]  h 身高 ， k 是前面比自己高的人
        //按照h 降序
        Arrays.sort(arr, new Comparator<int[]>() {
            @Override
            public int compare(int[] a, int[] b) {
                if (a[0] == b[0]) return a[1] - b[1];
                return b[0] - a[0];
            }
        });

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]);
            }
            System.out.print(",");
            //[[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
        }





    }
}
